var categoryName = getUrlParam('categoryName');
var companyobj = {start: 0, length: 5, categoryName: '企业新闻'}, cnewsCount, inewsCount;
var industryobj = {start: 0, length: 5, categoryName: '行业动态'};
queryModelNew(companyobj);
queryModelNew(industryobj);
queryNewsList(categoryName);
$('.seriesMobile-nav').on('click', 'li', function () {
    var eq = $(this).data('index');
    $(this).addClass('active').siblings().removeClass('active');
    $('.infCenterMobile-list').eq(eq).show().siblings().hide()
});
$('.more').click(function () {
    var type = $(this).data('type');
    if (type == 0 && cnewsCount > companyobj.start) {
        queryModelNew(companyobj);
    } else if (type == 1 && inewsCount > industryobj.start) {
      queryModelNew(industryobj);
    }
})

/**
 * 查询企业新闻的内容
 */
function queryNewsList(val) {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/news/selectAllList',
        data: {
            categoryName: val
        },
        success: function (data) {
            var newList = data.data,
                newHtml = "";
            $.each(newList, function (i, o) {
                newHtml += '<li><a href="../zlkx/'+o.id+'.html"><img src="/' + o.headImage + '"><div class="list-content">' +
                    '<h4>' + o.name + '</h4><p>' + o.introduce + '</p><span>发布日期：' + o.createTime + '</span></div></a></li>'
            });
            $(".informationPc-list").html(newHtml);
        }
    })
}

/**
 * 查询推荐的内容
 */
(function () {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/news/selectAllList',
        data: {
            isRecommend: 'y'
        },
        success: function (data) {
            var recommendList = data.data,
                recommendHtml = "",
                recommendPcHtml = "";
            $.each(recommendList, function (i, o) {
                recommendPcHtml += '<li class="li-introduce"><a href="../zlkx/'+o.id+'.html"><p class="p-name">'+o.name+'</p><p class="p-introduce">'+o.introduce+'</p><span>' + o.createTime + '</span></a></li>';
                recommendHtml += '<li><a href="../zlkx/'+o.id+'.html"><img src="/' + o.headImage + '"><div class="list-content">' +
                    '<p class="p-name">'+o.name+'</p><p class="p-introduce"><span>发布日期：' + o.createTime + '</span></div></a></li>'
            });
            $(".recommend-li").after(recommendPcHtml);//pc端的查询
            $(".recommend-list").html(recommendHtml);//移动端查询
            dotNews();

        }
    })
})();
/**
 * 查询最热的内容
 */
(function () {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/news/selectAllList',
        data: {
            isHot: 'y'
        },
        success: function (data) {
            var hotList = data.data,
                hotHtml = "",
                hotPcHtml = "";
            $.each(hotList, function (i, o) {
                hotPcHtml += '<li class="li-introduce"><a href="../zlkx/'+o.id+'.html"><p class="p-name">'+o.name+'</p><p class="p-introduce">'+o.introduce+'</p><span>' + o.createTime + '</span></a></li>';
                hotHtml += '<li><a href="../zlkx/'+o.id+'.html"><img src="/' + o.headImage + '"><div class="list-content">' +
                    '<p class="p-name">'+o.name+'</p><p class="p-introduce"><span>发布日期：' + o.createTime + '</span></div></a></li>'
            });
            $(".hotPC-li").after(hotPcHtml);
            $(".hotMobile-list").html(hotHtml);
            dotNews();
        }
    })
})();

function queryModelNew(obj) {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/front/news/selectPageList',
        data: obj,
        success: function (data) {
            var list = data.list, html = "";
            $.each(list, function (i, o) {
                html += '<li><a href="../zlkx/'+o.id+'.html"><img src="/' + o.headImage + '"><div class="list-content">' +
                    '<p class="p-name">'+o.name+'</p><p class="p-introduce">'+o.introduce+'</p><span>发布日期：' + o.createTime + '</span></div></a></li>'
            });
            if (obj.categoryName == '企业新闻') {
                $(".newMobile-list").append(html);
                companyobj.start += companyobj.length * 1;
                cnewsCount = data.recordsTotal;
            } else {
                $(".industry-list").append(html);
                industryobj.start += industryobj.length * 1;
                inewsCount = data.recordsTotal;
            }
        }
    })
};

